﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 工作日定义类别管理
    /// </summary>
    public class CdLeaveReason
    {
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.CdLeaveReason DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.CdLeaveReason model = new ElingOA6_Admin_DSJCJ.Model.CdLeaveReason();
            if (row != null)
            {
                if (row["FLeaveReasonCd"] != null)
                {
                    model.FLeaveReasonCd = row["FLeaveReasonCd"].ToString();
                }
                if (row["FLeaveReasonName"] != null)
                {
                    model.FLeaveReasonName = row["FLeaveReasonName"].ToString();
                }
                if (row["FClass"] != null)
                {
                    model.FClass = row["FClass"].ToString();
                }
                if (row["FIsSignOut"] != null)
                {
                    model.FIsSignOut = row["FIsSignOut"].ToString();
                }
                if (row["FIsStat"] != null)
                {
                    model.FIsStat = row["FIsStat"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLeaveReasonCd,FLeaveReasonName,FClass,FIsSignOut,FIsStat ");
            strSql.Append(" FROM dbo.t_cdLeaveReason ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.CdLeaveReason GetModel(string FLeaveReasonCd)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FLeaveReasonCd,FLeaveReasonName,FClass,FIsSignOut,FIsStat from dbo.t_cdLeaveReason ");
            strSql.Append(" where FLeaveReasonCd=@FLeaveReasonCd ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLeaveReasonCd", SqlDbType.NVarChar,6)			};
            parameters[0].Value = FLeaveReasonCd;

            ElingOA6_Admin_DSJCJ.Model.CdLeaveReason model = new ElingOA6_Admin_DSJCJ.Model.CdLeaveReason();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(ElingOA6_Admin_DSJCJ.Model.CdLeaveReason model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into dbo.t_cdLeaveReason(");
            strSql.Append("FLeaveReasonCd,FLeaveReasonName,FClass,FIsSignOut,FIsStat)");
            strSql.Append(" values (");
            strSql.Append("@FLeaveReasonCd,@FLeaveReasonName,@FClass,@FIsSignOut,@FIsStat)");
            SqlParameter[] parameters = {
					new SqlParameter("@FLeaveReasonCd", SqlDbType.NVarChar,6),
					new SqlParameter("@FLeaveReasonName", SqlDbType.NVarChar,20),
					new SqlParameter("@FClass", SqlDbType.NVarChar,1),
					new SqlParameter("@FIsSignOut", SqlDbType.NVarChar,1),
					new SqlParameter("@FIsStat", SqlDbType.NVarChar,1)};
            parameters[0].Value = model.FLeaveReasonCd;
            parameters[1].Value = model.FLeaveReasonName;
            parameters[2].Value = model.FClass;
            parameters[3].Value = model.FIsSignOut;
            parameters[4].Value = model.FIsStat;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.CdLeaveReason model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update dbo.t_cdLeaveReason set ");
            strSql.Append("FLeaveReasonName=@FLeaveReasonName,");
            strSql.Append("FClass=@FClass,");
            strSql.Append("FIsSignOut=@FIsSignOut,");
            strSql.Append("FIsStat=@FIsStat");
            strSql.Append(" where FLeaveReasonCd=@FLeaveReasonCd ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLeaveReasonName", SqlDbType.NVarChar,20),
					new SqlParameter("@FClass", SqlDbType.NVarChar,1),
					new SqlParameter("@FIsSignOut", SqlDbType.NVarChar,1),
					new SqlParameter("@FIsStat", SqlDbType.NVarChar,1),
					new SqlParameter("@FLeaveReasonCd", SqlDbType.NVarChar,6)};
            parameters[0].Value = model.FLeaveReasonName;
            parameters[1].Value = model.FClass;
            parameters[2].Value = model.FIsSignOut;
            parameters[3].Value = model.FIsStat;
            parameters[4].Value = model.FLeaveReasonCd;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string FLeaveReasonCd)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_cdLeaveReason ");
            strSql.Append(" where FLeaveReasonCd=@FLeaveReasonCd ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLeaveReasonCd", SqlDbType.NVarChar,6)			};
            parameters[0].Value = FLeaveReasonCd;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string FLeaveReasonCdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_cdLeaveReason ");
            strSql.Append(" where FLeaveReasonCd in (" + FLeaveReasonCdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
